home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Sherlock 2.0 / Sherlock_DevLib / sl.h < prev    next >
Text File  |  1996-04-04  |  10KB  |  364 lines

  1. /*
  2.      Sherlock master header file.
  3.  
  4.     source:  sl.h
  5.     started: November 4, 1993.
  6.     version:
  7.         April 4, 1996.
  8.             Added FTAG and FTAGV macros.
  9.         February 9, 1996.
  10.             Added support for C++.
  11.         November 15, 1995.
  12.             Added prototypes for sl_mac_xxx.c files.
  13.             Added prototype for sl_unwatch.
  14.         October 26, 1995
  15.             Optionally enalbe hidden Sherlock entry points with HIDDEN_SHERLOCK_ENTRIES.
  16.         Septermber 25, 1995
  17.             Added support for CodeWarrior.
  18.         July 6, 1994.
  19.             Added support for Tuple compiler.
  20.         January 7, 1994.
  21. */
  22.  
  23. /*
  24.     Make sure this file is included only once.
  25. */
  26. #pragma once
  27.  
  28. #ifndef SHERLOCK_H_
  29. #define SHERLOCK_H_
  30.  
  31. #ifdef __cplusplus    // 2/9/96
  32. extern "C" {
  33. #endif
  34.  
  35. #define SL_VERSION_NAME    "October 25, 1995"
  36.  
  37. /*
  38.     Set SHERLOCK_DEFINED to 0 or 1, depending on whether SHERLOCK is defined.
  39.  
  40.     The sherlock macro includes code only if SHERLOCK is defined.
  41. */
  42. #ifdef SHERLOCK
  43.     #define SHERLOCK_DEFINED 1
  44. #else
  45.     #define SHERLOCK_DEFINED 0
  46. #endif
  47.  
  48. /*
  49.     The following constants are predefined by their respective compilers:
  50.  
  51.     applec        use MPW on the Macintosh.
  52.     THINK_C        use THINK_C on the Macintosh 68K.
  53.     SYMANTEC_C    use SYMANTEC_C on MACintosh PPC.
  54. */
  55.  
  56. #include <stdio.h> /* Defines sprintf and size_t. */
  57.  
  58. #ifdef applec
  59.     #if 0 /* Do not include Toolbox code for MPW. */
  60.         #include <Types.h>            /* Defines Boolean and Point. */
  61.         #include <Events.h>            /* Defines EventRecord. */
  62.         #include <Menus.h>            /* Must precede redefinition of Menu Routines. */
  63.         #include <Quickdraw.h>        /* Defines RgnHandle. */
  64.     #endif
  65. #endif
  66.  
  67. #if defined(THINK_C) || defined(SYMANTEC_C) || defined(__MWERKS__)
  68.     #include <Types.h>            /* Defines Boolean and Point. */
  69.     #include <Errors.h>
  70.     #include <Events.h>            /* Defines EventRecord. */
  71.     #include <OSUtils.h>
  72.     #include <Menus.h>
  73.     #include <Quickdraw.h>        /* Defines RgnHandle. */
  74.     #include <SegLoad.h>
  75. #endif
  76.  
  77. /* 9/25/95 */
  78. #ifndef bool_defined
  79.     typedef int bool;
  80. #endif
  81.  
  82. /*
  83.     Define the format of statistics nodes.
  84.  
  85.     These nodes are used to keep all information related to tracepoints.
  86.     There is exactly one node per tracepoint, regardless of how many
  87.     times a tracepoint name appears throughout the code.
  88. */
  89. typedef struct sl_node_struct sl_node;
  90.  
  91. struct sl_node_struct {
  92.  
  93.     sl_node *        next;        /* pointer to next bucket. */
  94.     sl_node *        alpha;        /* alphabetical list. */
  95.     char *            name;        /* pointer to checkpoint name. */
  96.     unsigned long    calls;        /* # of calls to macros. */
  97.     unsigned long    time;        /* Time (in ticks). */
  98.     unsigned long    time2;        /* Cumulative time. */
  99.     int                  trace;          /* trace/wild flags. */
  100. };
  101.  
  102. #define SL_TRACE_BIT 0x01        /* TRUE: tracing enabled.        */
  103. #define SL_WILD_BIT     0x02        /* TRUE: enabled by wildcard.    */
  104.  
  105. typedef struct sl_watch_struct sl_wnode;
  106.  
  107. struct sl_watch_struct {
  108.     sl_wnode *    wnext;
  109.     char *        wp;            /* Pointer to the current block. */
  110.     char *        wsavep;        /* Pointer to the saved block. */
  111.     long        wlength;    /* Length of both blocks. */
  112.     char *        wtag;
  113. };
  114.  
  115. extern sl_wnode * sl_wlist;
  116.  
  117. /*
  118.     Global Sherlock variables.
  119. */
  120. extern long    sl_theTicks;        /* Ticks returned from sl_ret */
  121. extern long sl_min_margin;        /* Minimum stack margin. */
  122. extern long sl_margin_start;    /* Stack area (maximum stack margin). */
  123. extern bool sl_time_flag;        /* TRUE: report time in exit macros. */
  124. extern bool sl_use_adjust_flag;    /* TRUE: adjust time statistics in sl_dump.c. */
  125. extern unsigned long sl_count;    /* Time returned by interrupt routines. */
  126.  
  127. /*
  128.     Function prototypes.
  129. */
  130.  
  131.     /* sl_dump.c */
  132.     
  133.  
  134.     /* Aliases for values of TRUE and FALSE in flags. */
  135.     
  136.     #define SL_DUMP_ALL_STATS TRUE
  137.     #define SL_DUMP_ENABLED_STATS FALSE
  138.  
  139. void    sl_dump            (void);
  140. void    sl_dump_header    (bool dump_all_flag);
  141. void    sl_dump_name    (char * name);
  142. void     sl_dump_names    (bool dump_all_flag, char * dump_name);
  143. void    sl_dump_start    (void);
  144. void    sl_dump_subtotals(void);
  145. void    sl_dump_subtotal_start(void);
  146. void    sl_dump_totals    (void);
  147. void    sl_dump_wild    (void);
  148. void    sl_edump        (void);
  149. void    sl_dumpstk        (void);
  150. void    sl_hdump        (void);
  151.  
  152.     /* sl_init.c */
  153.  
  154. void    sl_init        (char * version);
  155. void    sl_off        (char *);
  156. void    sl_on        (char *);
  157. void    sl_parse    (int *,char **,char *,char *);
  158. int        sl_match    (char *s1, char *s2);
  159. void    sl_signon    (void);
  160. int        sl_wild        (char *s);
  161.  
  162.     /* sl_macro.c */
  163.  
  164. sl_node *        sl_find_name(char *s);
  165. void            sl_ovb        (void);
  166. void            sl_ovx        (void);
  167. int             sl_pxtrace    (char *);               /* TRACEPX */
  168. void            sl_unwatch    (char * p, long length);
  169. void            sl_watch    (void * p, long length, char * tag);
  170. void            sl_watchall    (void);
  171. void            sl_x        (char *);               /* TICKX */
  172. bool             sl_xb        (char *,bool);
  173. char            sl_xc        (char *,char);
  174. double          sl_xd        (char *,double);
  175. double          sl_xf        (char *,double);
  176. int             sl_xi        (char *,int);
  177. long            sl_xl        (char *,long);
  178. void *          sl_xp        (char *,void *);
  179. char *          sl_xs        (char *,char *);
  180. int             sl_xtrace    (char *);               /* TRACEX */
  181. unsigned int    sl_xui        (char *,unsigned int);
  182. unsigned long    sl_xul        (char *,unsigned long);
  183. void            sl_xv        (char *);
  184. void            sl2bstat    (sl_node **,char *);
  185. void            sl2btick    (sl_node **,char *);
  186. int                sl2btrace    (sl_node **,char *);
  187. int                sl2not        (sl_node **,char *);
  188. void            sl2ntick    (sl_node **,char *);
  189. int                sl2ntrace    (sl_node **,char *);
  190. int                sl2pbtrace    (sl_node **,char *);
  191. int                sl2pntrace    (sl_node **,char *);
  192. int                sl2ptrace    (sl_node **,char *);
  193. void            sl2stat        (sl_node **,char *);
  194. void            sl2tick        (sl_node **,char *);
  195. int                sl2trace    (sl_node **,char *);
  196.  
  197.     /* sl_time.c */
  198.  
  199. unsigned long    sl_adjust(sl_node * np, long val);
  200. void            sl_setadj    (void);
  201. void            sl_timetest    (void);
  202.  
  203.     /* sl_util.c */
  204.  
  205. char *        sl_callname    (int n);
  206. void        sl_clear    (void);
  207. void        sl_setname    (char *);
  208.  
  209.     /* sl_mac_menu.c, sl_mac_window.c */
  210.  
  211. void sl_enable_menu_items        (void);
  212. void sl_do_command                 (short item);
  213. void sl_install_sherlock_menu    (void);
  214.  
  215. /*
  216.     The SL_ENABLE and SL_DISABLE macros are used as signals to SPP.
  217.     They must always be defined and must never produce any expansion.
  218. */
  219. #define SL_DISABLE()
  220. #define SL_ENABLE()
  221.  
  222. /*
  223.     Define the actual Sherlock macros.
  224.     Sherlock macros produce "do nothing" code if SHERLOCK is not #define'd.
  225. */
  226.  
  227. #ifdef SHERLOCK
  228.  
  229.     #ifndef FTAG
  230.         #define FTAG(s)  char * ftag = s
  231.     #endif
  232.     #ifndef FTAGV
  233.         #define FTAGV(s) char * ftagv = s
  234.     #endif
  235.  
  236.     #define SL_CALLNAME(n)                sl_callname(n)
  237.     #define SL_CLEAR()                  sl_clear()
  238.     #define SL_DUMP()                      sl_dump()
  239.     #define SL_INIT()                     sl_init(SL_VERSION_NAME)
  240.  
  241.     #define SL_NAME(a,b)                static char a [] = b
  242.     #define SL_NOT(a,b)     {static sl_node *sl_h_=0; if(!sl2ntrace(&sl_h_,a)){b;}}
  243.     #define SL_NOTP(a,b) {static sl_node *sl_h_=0; if(!sl2pntrace(&sl_h_,a)){b;}}
  244.     #define SL_OFF(s)                   sl_off(s)
  245.     #define SL_ON(s)                       sl_on(s)
  246.     #define SL_OVB()                    sl_ovb()
  247.     #define SL_OVX()                    sl_ovx()
  248.     #define SL_PARSE(argc,argv,on,off)    sl_parse(&argc,argv,on,off)
  249.     #define SL_SIGNON()                    sl_signon()
  250.     #define SL_WATCH(a,b,c)                sl_watch(a,b,c)
  251.     #define SL_WATCH_ALL()                sl_watch_all()
  252.  
  253.     #define STAT(a)        {static sl_node *sl_h_=0; sl2stat(&sl_h_,a);}
  254.     #define STATB(a)    {static sl_node *sl_h_=0; sl2bstat(&sl_h_,a);}
  255.     #define STATX(a)    {sl_xtrace(a);}     /* Ignore the return code. */
  256.  
  257.     #define TICK(a)        {static sl_node *sl_h_=0; sl2tick(&sl_h_,a);}
  258.     #define TICKB(a)    {static sl_node *sl_h_=0; sl2btick(&sl_h_,a);}
  259.     #define TICKN(a)    {static sl_node *sl_h_=0; sl2ntick(&sl_h_,a);}
  260.     #define TICKX(a)    sl_x(a)
  261.  
  262.     #define TICKX_BOOL(a,b)        sl_xb(a,b)
  263.     #define TICKX_CHAR(a,c)        sl_xc(a,c)
  264.     #define TICKX_DOUBLE(a,d)    sl_xd(a,d)
  265.     #define TICKX_FLOAT(a,f)    sl_xf(a,f)
  266.     #define TICKX_INT(a,i)        sl_xi(a,i)
  267.     #define TICKX_LONG(a,l)        sl_xl(a,l)
  268.     #define TICKX_PTR(a,p)        sl_xp(a,p)
  269.     #define TICKX_STRING(a,s)    sl_xs(a,s)
  270.     #define TICKX_UINT(a,u)        sl_xui(a,u)
  271.     #define TICKX_ULONG(a,u)    sl_xul(a,u)
  272.     #define TICKX_VOID(a)        sl_xv(a)
  273.  
  274.     #define TRACE(a,b)    {static sl_node *sl_h_=0; if(sl2trace(&sl_h_,a)) {b;}}
  275.     #define TRACEB(a,b)    {static sl_node *sl_h_=0; if(sl2btrace(&sl_h_,a)){b;}}
  276.     #define TRACEN(a,b)    {static sl_node *sl_h_=0; if(sl2ntrace(&sl_h_,a)){b;}}
  277.     #define TRACEX(a,b)    {if(sl_xtrace(a)) {b;}}
  278.  
  279.     #define TRACEP(a,b)  {static sl_node *sl_h_=0; if(sl2ptrace(&sl_h_,a)) {b;}}
  280.     #define TRACEPB(a,b) {static sl_node *sl_h_=0; if(sl2pbtrace(&sl_h_,a)){b;}}
  281.     #define TRACEPN(a,b) {static sl_node *sl_h_=0; if(sl2pntrace(&sl_h_,a)){b;}}
  282.     #define TRACEPX(a,b) {if(sl_pxtrace(a)) {b;}}
  283.     
  284.     /*
  285.         No calls to the following Macintosh traps should appear outside of mac_gui.c.
  286.         The following macros make *sure* they do not.
  287.     */
  288.     
  289.     #if defined(THINK_C) || defined(SYMANTEC_C) || defined(__MWERKS__)
  290.         #ifdef HIDDEN_SHERLOCK_ENTRIES
  291.             #define GetNextEvent(a,b)        w_event(a,b,0L,((RgnHandle)0),0)
  292.             #define WaitNextEvent(a,b,c,d)    w_event(a,b,c,d,1)
  293.             #define MenuSelect(a)            w_menuSelect(a)
  294.             #define DrawMenuBar()            w_drawMenuBar()
  295.         #endif
  296.     #endif
  297.  
  298. #else /* SHERLOCK not defined. */
  299.  
  300.     /* Null macro definitions for all Sherlock macros. */
  301.     
  302.     #ifndef FTAG
  303.         #define FTAG(s) char * ftag = NULL
  304.     #endif
  305.     #ifndef FTAGV
  306.         #define FTAGV(s) char * ftag = NULL
  307.     #endif
  308.  
  309.     #define SL_CALLNAME(n)        ""
  310.     #define SL_CLEAR()
  311.     #define SL_DUMP()
  312.     #define SL_INIT()
  313.     #define SL_MAC_INIT(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)
  314.     #define SL_NAME(a,b)
  315.     #define SL_NOT(a,b)
  316.     #define SL_NOTP(a,b)
  317.     #define SL_OFF(s)
  318.     #define SL_ON(s)
  319.     #define SL_OVB()
  320.     #define SL_OVX()
  321.     #define SL_PARSE(argc,argv,on,off)
  322.     #define SL_SIGNON()
  323.     #define SL_WATCH(a,b,c)
  324.     #define SL_WATCH_ALL()
  325.  
  326.     #define STAT(a)
  327.     #define STATB(a)
  328.     #define STATX(a)
  329.  
  330.     #define TICK(a)
  331.     #define TICKB(a)
  332.     #define TICKN(a)
  333.     #define TICKX(a)
  334.  
  335.     #define TICKX_BOOL(a,b)
  336.     #define TICKX_CHAR(a,c)
  337.     #define TICKX_DOUBLE(a,d)
  338.     #define TICKX_FLOAT(a,f)
  339.     #define TICKX_INT(a,i)
  340.     #define TICKX_LONG(a,l)
  341.     #define TICKX_PTR(a,p)
  342.     #define TICKX_STRING(a,s)
  343.     #define TICKX_UINT(a,u)
  344.     #define TICKX_ULONG(a,u)
  345.     #define TICKX_VOID(a)
  346.  
  347.     #define TRACE(a,b)
  348.     #define TRACEB(a,b)
  349.     #define TRACEN(a,b)
  350.     #define TRACEX(a,b)
  351.  
  352.     #define TRACEP(a,b)
  353.     #define TRACEPB(a,b)
  354.     #define TRACEPN(a,b)
  355.     #define TRACEPX(a,b)
  356.     
  357. #endif /* ifdef SHERLOCK */
  358.     
  359. #ifdef __cplusplus    // 2/9/96
  360. }
  361. #endif
  362.  
  363. #endif /* ifndef SHERLOCK_H_ */
  364.